package com.example.soul;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import app.com.R;

public class RegistActivity extends AppCompatActivity {
    EditText mEtName,mEtPassword,mEtEmail;
    Button mBtRegister;

    //@Override
   // *protected void onCreate(Bundle savedInstanceState) {
        //super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_regist);
        //mBtRegister.findViewById(R.id.bt_register);
        //mEtName.findViewById(R.id.et_name);
        //mEtPassword.findViewById(R.id.et_password);
        //mEtEmail.findViewById(R.id.et_email);

    //}
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        mBtRegister.findViewById(R.id.bt_register);
        mEtName.findViewById(R.id.et_name);
        mEtPassword.findViewById(R.id.et_password);
        mEtEmail.findViewById(R.id.et_email);
    }


    public void register(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String url1="http://localhost:8080/WorldCupApp/user/register";
                try {
                    URL url=new URL(url1);
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setRequestProperty("Content-type","application/json");
                    conn.setRequestMethod("POST");
                    conn.setDoOutput(true);
                    conn.setDoInput(true);
                    //数据
                    JSONObject jsonObject=new JSONObject();
                    jsonObject.put("name",mEtName.getText().toString());
                    jsonObject.put("password",mEtPassword.getText().toString());
                    jsonObject.put("email",mEtEmail.getText().toString());

                    String data=jsonObject.toString();
                    //发送数据

                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}